package com.qp.basics.estivate.utils;

import java.text.CollationKey;
import java.text.Collator;
import java.util.Comparator;
import java.util.TreeMap;

public class KeysSortedMap<K, V> extends TreeMap<K, V> {

	static class KeysSortedComparator<K> implements Comparator<K> {

		private Collator collator = Collator.getInstance();

		@Override
		public int compare(Object o1, Object o2) {
			if (o1 == null || o2 == null) {
				return 0; // if one param is empty, return 0
			}
			CollationKey key1 = collator.getCollationKey(o1.toString()
					.toLowerCase());
			CollationKey key2 = collator.getCollationKey(o2.toString()
					.toLowerCase());
			return (key1.compareTo(key2));
		}
	}

	private final static Comparator comparator = new KeysSortedComparator();

	public KeysSortedMap() {
		super(comparator);
	}
}
